﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes {
    import Engine.Helpers.*;
    import Engine.*;

    public class ParkingLot extends Road {

        protected var m_decoration:FauxDecoration = null;
        protected var m_decoOffset:Vector3;

        public function ParkingLot(_arg1:String=null){
            var _local4:String;
            this.m_decoOffset = new Vector3(0, 0);
            super(_arg1);
            var _local2:XML = getItem().xml;
            var _local3:XMLList = _local2.attached_deco;
            _local2 = _local3[0];
            if (_local2){
                _local4 = _local2.@deco;
                this.m_decoOffset.x = _local2.@xOffset;
                this.m_decoOffset.y = _local2.@yOffset;
                this.m_decoOffset.z = _local2.@zOffset;
                if (((_local4) && ((_local4.length > 0)))){
                    this.m_decoration = new FauxDecoration(_local4);
                    this.m_decoration.setOuter(Global.world);
                };
            };
        }
        override public function loadObject(_arg1:Object):void{
            super.loadObject(_arg1);
            if (this.m_decoration){
                this.m_decoration.rotateToDirection(m_direction);
                this.setPosition(m_position.x, m_position.y, m_position.z);
            };
        }
        override public function setPosition(_arg1:Number, _arg2:Number, _arg3:Number=0):void{
            var _local4:Number;
            var _local5:Number;
            var _local6:Vector3;
            var _local7:Number;
            var _local8:Number;
            super.setPosition(_arg1, _arg2, _arg3);
            if (this.m_decoration){
                _local4 = this.m_decoOffset.x;
                _local5 = this.m_decoOffset.y;
                _local6 = this.getSize().scale(0.5);
                _local4 = (_local4 - _local6.x);
                _local5 = (_local5 - _local6.y);
                switch (m_direction){
                    case Constants.DIRECTION_SW:
                        _local7 = _local4;
                        _local8 = _local5;
                        break;
                    case Constants.DIRECTION_SE:
                        _local7 = -(_local5);
                        _local8 = _local4;
                        break;
                    case Constants.DIRECTION_NW:
                        _local7 = _local5;
                        _local8 = -(_local4);
                        break;
                    case Constants.DIRECTION_NE:
                        _local7 = -(_local4);
                        _local8 = -(_local5);
                        break;
                };
                _local4 = (_local7 + _local6.x);
                _local5 = (_local8 + _local6.y);
                this.m_decoration.setPosition((_arg1 + _local4), (_arg2 + _local5), _arg3);
                this.m_decoration.conditionallyReattach(true);
            };
        }
        override public function rotate():void{
            super.rotate();
            if (this.m_decoration){
                this.m_decoration.rotate();
                this.setPosition(m_position.x, m_position.y, m_position.z);
            };
            Global.world.citySim.roadManager.updateAllRoadTiles();
            Global.world.citySim.roadManager.updateRoads(this);
        }
        override public function rotateToDirection(_arg1:int):void{
            super.rotateToDirection(_arg1);
            if (this.m_decoration){
                this.m_decoration.rotateToDirection(_arg1);
            };
        }
        override public function attach():void{
            super.attach();
            if (this.m_decoration){
                this.m_decoration.attach();
            };
        }
        override public function detach():void{
            super.detach();
            if (this.m_decoration){
                this.m_decoration.detach();
            };
        }
        override protected function updateAdjacent():void{
            var _local1:int;
            var _local6:int;
            if (m_adjacentRoads != null){
                return;
            };
            super.updateAdjacent();
            for each (_local1 in m_adjacentStretch) {
                m_adjacentRoads[_local1] = null;
            };
            m_adjacentStretch = [];
            for each (_local1 in m_adjacentTight) {
                m_adjacentRoads[_local1] = null;
            };
            m_adjacentTight = [];
            _local1 = m_direction;
            if (_local1 < 0){
                _local1 = 0;
            };
            if (_local1 >= DIRECTION_MAX){
                _local1 = 0;
            };
            var _local2:int = (DOWN + _local1);
            if (_local2 >= DIRECTION_MAX){
                _local2 = (_local2 - DIRECTION_MAX);
            };
            var _local3:int = (UP + _local1);
            if (_local3 >= DIRECTION_MAX){
                _local3 = (_local3 - DIRECTION_MAX);
            };
            var _local4:Road = m_adjacentRoads[_local2];
            if ((_local4 is ParkingLot)){
                _local4 = null;
            };
            var _local5:int;
            while (_local5 < m_adjacentPartial.length) {
                _local6 = m_adjacentPartial[_local5];
                if (_local6 == _local3){
                    m_adjacentRoads[_local6] = null;
                    m_adjacentPartial.splice(_local5, 1);
                    _local5--;
                } else {
                    if (((_local4) && (!((_local6 == _local2))))){
                        if (!(m_adjacentRoads[_local6] is ParkingLot)){
                            m_adjacentRoads[_local6] = null;
                            m_adjacentPartial.splice(_local5, 1);
                            _local5--;
                        };
                    };
                };
                _local5++;
            };
            _local5 = 0;
            while (_local5 < m_adjacent.length) {
                _local6 = m_adjacent[_local5];
                if (_local6 == _local3){
                    m_adjacentRoads[_local6] = null;
                    m_adjacent.splice(_local5, 1);
                    _local5--;
                } else {
                    if (((_local4) && (!((_local6 == _local2))))){
                        if (!(m_adjacentRoads[_local6] is ParkingLot)){
                            m_adjacentRoads[_local6] = null;
                            m_adjacent.splice(_local5, 1);
                            _local5--;
                        };
                    };
                };
                _local5++;
            };
        }
        override protected function getCurrentImage():ItemImageInstance{
            var _local1:ItemImageInstance = m_item.getCachedImage(m_state, this, m_direction, m_statePhase);
            return (_local1);
        }
        override public function cornerShouldAdjust(_arg1:Road, _arg2:int):Boolean{
            return (false);
        }
        override public function shouldAdjust(_arg1:Road, _arg2:int):Boolean{
            return (false);
        }
        override public function prepareToDrop(_arg1:Vector3, _arg2:Vector2):Road{
            return (this);
        }
        override public function isPositionValid():Boolean{
            return (false);
        }

    }
}//package Classes 
